<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Entrance</title>
    <script src="./font/iconfont.js"></script>
    <link rel="stylesheet" href="./font/iconfont.css">
    <!-- 兼容IE -->
    <script src="./js/polyfill.min.js"></script>
    <script src="./js/babel.min.js"></script>
    <script src="./layui/layui.js"></script>
    <link rel="stylesheet" href="./layui/css/layui.css" media="all">
    <link rel="stylesheet" href="./css/login.css">
    <script src="./js/axios.min.js"></script>
</head>

<body>
    <div class="wrapper" id="app">
        <div class="iconWrapper">
            <svg class="icon" aria-hidden="true" width="300px" height="300px">
                <use xlink:href="#icon-3"></use>
            </svg>
            <p> HYPERION SYSTEM </p>
        </div>
        <div class="loginWrapper">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">ADMIN ID</label>
                    <div class="layui-input-block">
                        <input type="text" name="adminId" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">PASSWORD</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn submitBtn" lay-submit lay-filter="login">LOGIN</button>
                    </div>
                </div>
            </form>
        </div>
</body>
<script>
    console.log(layui.table)
    layui.use(['layer', 'form'], function () {
        var form = layui.form;
        var layer = layui.layer;
        form.on('submit(login)', function (data) {
            console.log("!")
            axios.post('http://127.0.0.1:8080/login', data.field)
                .then((response) => {
                    if (response.data.rtCode == 'Y') {
                        window.location.href = "http://127.0.0.1:5500/astrolabe.html"
                    } else {
                        layer.msg("Username or password is incorrect")
                    }
                })
                .catch((error) => {
                    layer.msg("Network error")
                });
            return false;
        });
    });
</script>

</html>